package com.link.base.base.invloc.controller;

import com.link.base.base.invloc.model.InvProdLoc;
import com.link.base.base.invloc.model.InventoryModel;
import com.link.base.base.invloc.service.InvProdLocService;
import com.link.base.base.product.model.Product;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.model.BasicModel;
import com.link.core.basic.query.QueryParams;
import com.link.core.basic.service.BasicService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: unknown
 * created: unknown
 * comments:
 */
@Controller
@RequestMapping("/link/invProLoc")
public class InvProdLocController extends BasicController<InvProdLoc> {

    @Resource
    private InvProdLocService invProdLocService;

    @Override
    public BasicService<InvProdLoc> getBasicService() throws Exception {
        return invProdLocService;
    }


    /**
     * 品牌商查看库存列表
     *
     * @return
     */
    @RequestMapping(value = "/queryVendorInvprodPage", method = RequestMethod.POST)
    @ResponseBody
    public Map<String, Object> queryVendorInvprodPage(@JsonParam QueryParams qps,@JsonParam InventoryModel inventoryModel) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            InventoryModel im = (InventoryModel) BasicModel.transformClass(inventoryModel, qps);
            List<InventoryModel> list = invProdLocService.queryVendorInvprodPage(im);
            result.put("rows", list);
            result.put("success", true);
            result.put("total", getCount((BasicModel) im, list.size()));
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

    @RequestMapping(value = "/queryBuySuggestReport")
    public Map<String, Object> queryBuySuggestReport(@JsonParam QueryParams qps,@JsonParam Product product) {
        Map<String, Object> result = new HashMap<String, Object>();
        try {
            List<Product> list = invProdLocService.queryBuySuggestReport(product);
            result.put("rows", list);
            result.put("success", true);
            result.put("total", getCount((BasicModel) product, list.size()));
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("message", e.getMessage());
        }
        return result;
    }

}
